﻿<link rel="stylesheet" href="/static/css/jquery-validate.css" />
<div id="divLogin" class="hide">
    <div class="loginPart">
        <h1 class="log-title" id="h1Login">社团账号登录</h1>
        <div class="log-content">
            <form id="formValidate">
                <div class="form_control top">
                    <input type="text" id="UserName" data-tip="请输入您的手机" data-valid="isNonEmpty||isMobile" data-error="手机不能为空||手机格式不正确" placeholder="请输入您的手机号码" class="log-f-mail required" />
                </div>
                <!-- <input type="text" id="WeChart" class="log-f-mail" placeholder="验证码" /> <img id="valiCode" style="cursor: pointer;" src="/api/login/GetValidateCode" alt="验证码" /> -->
                <div class="reg-t-code clearfix mt20">
                    <div class="form_control veriCode top">
                        <input type="text" id="WeChart" data-tip="请输入验证码" data-valid="isNonEmpty" data-error="验证码不能为空" class="log-f-mail required" placeholder="请输入验证码" />
                    </div>
                    <img id="valiCode" class="codeImg" src="/api/login/GetValidateCode" alt="验证码" />
                </div>
                <div class="form_control mt10 top">
                    <input type="password" id="Password" data-tip="请输入密码" data-valid="isNonEmpty||between:6-16" data-error="密码不能为空||密码长度6-16位" placeholder="请输入密码" class="log-f-pwd required" />
                </div>
                <input type="button" class="log-f-sub mt20" onclick="Login();" value="登 录" />
            </form>
            <p class="log-bottom mt10 clearfix">
                <a href="/forgetPwd.html" class="fl">忘记密码？</a>
                <a id="btnRegister" href="/personal/register.html" class="fr">免费注册申请</a>
            </p>
            <a href="/login.html?type=Company" class="mt20 main-color fr" id="pChangeLogin">点击进入企业账号登录</a>
        </div>
        <div id="divTwoLogin" class="hide">
            <div class="log-tab clearfix">
                <a href="/login.html?type=Personal" class="mt10 colorLGray fl">社团账号登录</a>
                <a href="/login.html?type=Company" class="mt10 colorLGray fr">企业账号登录</a>
            </div>
        </div>
    </div>
</div>
<!--已登录-->
<div id="divLogged" class="hide">
    <div class="logged">
        <div class="logg-img">
            <img id="imgLogin" src="/static/images/loginImg.png" />
            <a href="/my/myInfo.html" class="logg-i-btn">修改资料</a>
        </div>
        <p class="mt10" id="pName"></p>
        <p class="mt10">当前等级：<span id="snanGrade">三星级</span></p>
        <p class="mt10">欢迎回来，快乐生活每一个!</p>
        <!--<p class="mt20"><span>社团活动筹备100</span> | <span>企业赞助收藏100</span></p>-->
        <input type="button" id="btnRelease" value="发布活动" onclick="ReleseProject()" class="logg-btn mt20" />
        <input type="button" id="btnRean" value="赚钱去" onclick="location.href = '/org.html?type=Student'" class="logg-btn mt20 hide" />
    </div>
</div>
<script src="/static/js/self/jquery-validate.js"></script>
<script>

    common.validator($('form'));

    var user = common.GetUser();
    var userType = "";
    var loginType;

    function AfterLoginCompleted(ctx) {
        if (ctx == null) {
            common.alertMessage("无数据.");
            return;
        }

        common.PutStorageSession("user", JSON.stringify(ctx.ResponseObj));

        window.location = "/my/myInfo.html";
    }

    function Login() {

        var values = common.GetCtrlValues({
            ContentID: "formValidate"
        })

        values.UserType = userType;
        if (userType.toLowerCase() == "agent") {
            common.showMessage("代理官正在完善中，敬请期待"
            )
            return
        }

        if ($("#formValidate").validate('submitValidate')) {
            common.commonAjax({ type: 'Post', url: '/api/user/post', data: values, sMethod: AfterLoginCompleted });
        } else {
            alert("请填写正确的登录信息");
        }
    }

    function AfterCompleted(ctx) {
        if (ctx == null) {
            common.alertMessage("无数据.");
            return;
        }

        $("#pName").html(ctx.ResponseDict.Name);
        //$("#snanGrade").html(ctx.ResponseDict.Grade);
        //$("#imgLogin").attr("src", ctx.ResponseDict.LogoPath);
    }

    $("#valiCode").bind("click", function () {
        this.src = "/api/Login/GetValidateCode?time=" + (new Date()).getTime();
    });

    function ReleseProject() {
        common.commonAjax({ type: 'Get', url: '/api/user/HasVerified', sMethod: AfterVerified });
    }

    function AfterVerified(ctx) {
        if (ctx == null) {
            common.alertMessage("无数据.");
            return;
        }

        if (ctx.ResponseDict.HasVerified == "Y") {
            window.location = "/release.html";
        }
        else {
            common.showMessage(ctx.ResponseDict.Message, function () {
                if (loginType == 1)
                    window.location = "/company/register.html";
                else
                    window.location = "/personal/register.html";
            })
        }
    }

    function Init(type) {

        userType = type;
        var pChangeLogin = $("#pChangeLogin");
        var h1Login = $("#h1Login");
        var btnRegister = $("#btnRegister");
        switch (type) {
            case "Company":
                h1Login.html("企业账号登录");
                pChangeLogin.html("点击进入社团账号登录");
                pChangeLogin.attr("href","/login.html?type=Personal");
                btnRegister.attr("href", "/company/register.html");
                break;
            case "Agent":
                h1Login.html("代理官账户登录");
                pChangeLogin.hide();
                $("#divTwoLogin").show();
                btnRegister.attr("href", "/agent/register.html");
                break;
        }
    }

    if (common.checkValue(user)) {

        $("#divLogged").removeClass().show();

        loginType = common.GetUserType();
        if (loginType == 3) {
            $("#btnRelease").hide();
            $("#btnRean").show();
        }
        else
            $("#btnRean").hide();

        common.commonAjax({ type: 'Get', url: '/api/user/Get', sMethod: AfterCompleted });
    }
    else {

        $("#divLogin").removeClass().show();
    }
</script>
